//
//  UIView+HKExtension.swift
//  App架构Swift
//
//  Created by 胡锦涛 on 2019/2/19.
//  Copyright © 2019 胡锦涛. All rights reserved.
//

import UIKit
//MARK: UIView扩展-frame
extension UIView {
    
    /// X
    public var hk_left: CGFloat{
        get{
            return self.frame.origin.x
        }
        set{
            var r = self.frame
            r.origin.x = newValue
            self.frame = r
        }
    }
    
    /// Y
    public var hk_top: CGFloat{
        get{
            return self.frame.origin.y
        }
        set{
            var r = self.frame
            r.origin.y = newValue
            self.frame = r
        }
    }
    
    /// 右边界的X值
    public var hk_right: CGFloat{
        get{
            return self.hk_left + self.hk_width
        }
        set{
            var r = self.frame
            r.origin.x = newValue - frame.size.width
            self.frame = r
        }
    }
    
    /// 下边界的Y值
    public var hk_bottom: CGFloat{
        get{
            return self.hk_top + self.hk_height
        }
        set{
            var r = self.frame
            r.origin.y = newValue - frame.size.height
            self.frame = r
        }
    }
    
    /// centerX
    public var hk_centerX : CGFloat{
        get{
            return self.center.x
        }
        set{
            self.center = CGPoint(x: newValue, y: self.center.y)
        }
    }
    
    /// centerY
    public var hk_centerY : CGFloat{
        get{
            return self.center.y
        }
        set{
            self.center = CGPoint(x: self.center.x, y: newValue)
        }
    }
    
    /// width
    public var hk_width: CGFloat{
        get{
            return self.frame.size.width
        }
        set{
            var r = self.frame
            r.size.width = newValue
            self.frame = r
        }
    }
    /// height
    public var hk_height: CGFloat{
        get{
            return self.frame.size.height
        }
        set{
            var r = self.frame
            r.size.height = newValue
            self.frame = r
        }
    }
    
    /// origin
    public var origin: CGPoint{
        get{
            return self.frame.origin
        }
        set{
            self.hk_left = newValue.x
            self.hk_top = newValue.y
        }
    }
    
    /// size
    public var size: CGSize{
        get{
            return self.frame.size
        }
        set{
            self.hk_width = newValue.width
            self.hk_height = newValue.height
        }
    }
    
}

//MARK:UIView圆角属性
extension UIView {
    
    ///圆角
    func hk_round () {
        self.layer.cornerRadius = self.hk_height/2;
        self.layer.masksToBounds = true
    }
    
    ///圆角
    func hk_addBorder(_ bColor:UIColor, _ bWidth:CGFloat) {
        self.layer.borderColor = bColor.cgColor
        self.layer.borderWidth = bWidth
    }
}
